package fr.epsi.ressources;

import fr.epsi.studentsmaps.MapUserActivity;
import fr.epsi.studentsmaps.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class MapImageView extends ImageView {
	
	int x;
	int y;
	
	Point hg,hd,bg,bd;
	
	Context context;
	
	Epsirooms epsi;
	
	public void setDimension (int x, int y)
	{
		this.x = x;
		this.y = y;
	}


	public MapImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		this.context = context;
		epsi = new Epsirooms();

	}
	
	@Override
	 public void draw(Canvas canvas) {
	  super.draw(canvas);
	  

	  	int width = canvas.getWidth();
	  	int height = canvas.getHeight();
	  	
	 	DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
	  	float dp = 14f;
	  	float fpixels = metrics.density * dp;
	  	int pixels = (int) (fpixels + 0.5f);
	  	
	  	
	  	Paint pText = new Paint();
	  	//pText.setColor(Color.RED);
	  	
	  	pText.setColor(Color.rgb(82, 121, 132));
	  	pText.setStrokeWidth(14);
	  	pText.setTypeface(Typeface.create(Typeface.DEFAULT,Typeface.BOLD));
	  	pText.setTextSize(pixels);
	  	
	  	
	  	Paint pPoint = new Paint();
	  	pPoint.setColor(Color.GREEN);
	  	pPoint.setStrokeWidth(14);
	  	pPoint.setTypeface(Typeface.create(Typeface.DEFAULT,Typeface.BOLD));
	  	pPoint.setTextSize(pixels);


	  	for(int i = 0; i < epsi.roomList.size();i++)
	  	{
	  		if(epsi.getRoom(i).etage == MapUserActivity.etage)
	  		{
	  			canvas.drawText(epsi.getRoom(i).display,(float)(width* ((epsi.getRoom(i).relativeX)/100)  - ((pText.descent() + pText.ascent()) / 2)/*- pixels*((epsi.getRoom(i).display.length())/2.0f)*/), (float)(height* ((epsi.getRoom(i).relativeY)/100)), pText);
		  		canvas.drawPoint((float)(width* (epsi.getRoom(i).relativeX)/100),(float)(height* ((epsi.getRoom(i).relativeY)/100)), pPoint);

	  		}
	  	}


	 }
	
	 private float dpFromPx(float px)
	 {
	     return px / this.getResources().getDisplayMetrics().density;
	 }


	 private float pxFromDp(float dp)
	 {
	     return dp * this.getResources().getDisplayMetrics().density;
	 }


}